Repository navigation
GPT-OSS: match client stop sequences in the Harmony final message only (fixes reasoning-only empty answers) - #1645
Conversation
The engine matched `stop` against every generated character, including the private Harmony analysis. A sequence that appeared while gpt-oss reasoned ended the request before any answer: finish_reason "stop", reasoning only, empty content. On provider 0.10.4 with production gpt-oss-20b weights, stop ["."] did this to 36/36 requests and ["\n\n"] to 14/36 (0/36 without a stop); each cut reasoning is an exact prefix of its same-seed no-stop twin, which went on to answer. ModelEOSPolicy.stopStringScope gives GPT-OSS the Harmony final-channel scope (<|channel|>final ... <|message|> up to <|end|>/<|return|>/<|call|>/<|start|>). It travels with the EOS policy: EngineV2SlotFactory -> makeBridge -> EngineV2Bridge -> CBv2Request.stopStringScope, and the matched-sequence replay uses the same scope. Other models keep whole-output matching. Bumps libs/mlx-swift-lm to 38b90ed1 (fix/harmony-final-stop-scope), which adds the scope to StopHoldback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Threat model review — advisoryReviewed head Review not completed for this head. Previous findings are superseded, not confirmed resolved. Reviewers: anthropic/claude-sonnet-5.5: first pass completed; anthropic/claude-opus-5.5: selected depth completed (3 batches); openai/gpt-6.1-sol: selected depth completed (2 batches) Scan incomplete: 3 file(s) could not be fully read as text. Binary, Git LFS and submodule changes require manual review. Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging. Human review required: CI did not complete the security review. A maintainer must review the saved findings and remaining scope. A green advisory job is not security clearance; do not manually rerun the paid scan. Coverage: 143/143 source units; cross-file integration complete. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned. Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 32 reused batch(es), 0 provider cache-hit tokens. Saved findings and earlier report · Historical findings are not confirmed resolved. Bedrock: 5 request(s), 143004 uncached + 0 cache-read + 45218 cache-write input / 4085 output tokens; 0 request(s) with unknown usage. OpenRouter backup used 0 time(s). Dollar amounts above cover OpenRouter only; AWS billing is reconciled separately. |
libs/mlx-swift-lm moves to main 25bcd63f, the squash merge of Layr-Labs/mlx-swift-lm#369 (the Harmony final-channel stop scope this PR depends on). SDK main calls mlx-swift APIs newer than the pinned M5 hotfix (MLXFast fencedInputs), so the stack moves with it to the revision SDK main declares, as #1596 did: libs/mlx-swift c633d221 (nested mlx 72dffa2d, mlx-c 2ac897e3) and libs/mlx 72dffa2d. All three are on their repos' main. 72dffa2d carries the NAX head-dim split attention JIT fix (mlx main 6bc9de5b), the same get_steel_attention_nax_kernel change as the 0.10.3 hotfix 31f550af. Provider adaptations for the new SDK enum cases, behavior-preserving: - MLXServerGenerationEvent.logprobs is token metadata, handled like .info by the GLM and JSON answer-format observers (the provider streams logprobs through its own channel and emits no such events today). - MLXOpenAIServiceError.responseFormatCutOffByMaxTokens is the case the SDK split out of invalidResponseFormatOutput for a structured answer cut off by max_tokens; it keeps that case's 422 and retryable classification. Verified on M5 Max: Gemma 4 26B QAT serves an 8,204-token prompt (the 0.10.2 crash path) with an 8,192-token prefix hit on repeat; gpt-oss-20b stop ["."] still returns "The capital of Australia is Canberra". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The re-pinned mlx-swift-lm adds MLXServerGenerationEvent.logprobs. Seven test helpers switch exhaustively over events; each treats it like its existing non-content cases (.info / skipped). No assertion changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… into fix/gptoss-stop-in-reasoning Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Attempt 2 of run 40756992782 failed test_cli_result_write_failure_preserves_original_error_and_findings: the test inherits the runner's GITHUB_RUN_ATTEMPT=2, so the budget runner reports MANUAL_SCAN_RERUN_DISABLED. Attempt 1 on the same tree passed. No code change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#1645 now pins mlx-swift-lm 25bcd63f (#369 merged on SDK main), mlx-swift c633d221 and mlx 72dffa2d. The only conflict was the mlx-swift-lm pin. The two engine commits of this PR (95e1d2b9, b5d4c754 on branch fix/reasoning-stop-scope-exclude) are replayed onto 25bcd63f as 50ee329a and 25e65afc (branch fix/reasoning-stop-scope-exclude-on-25bcd63f), with an identical diff, and the pin moves there. Verified on the merged tree: SDK CBv2Sampling 55/55 (stop holdback 27/27); provider swift-testing 469 tests in 68 suites, XCTest 37/38 with the one failure only needing MIMO_PROMPT_ARTIFACT_DIRECTORY, which passes with the CI fixture. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ares Layr-Labs/mlx-swift-lm#368 was squash-merged as 2beb401f, so this branch's former SDK pin 76ff231b (#368's head) is not on SDK main. Every gitlink now points at a commit on its fork's main: - libs/mlx-swift-lm 76ff231b -> 2beb401f, the tip of SDK main and the #368 squash. Merging 76ff231b into the previous main (25bcd63f) gives exactly 2beb401f's tree, so #368 (demandedLatestCheckpointMinimumTokens) is unchanged. The pin also brings what SDK main gained since master's aee6ebb6: the tensor-parallel engine (#308), Qwen tensor batching (#352) and the optional stop-string scope (#369). - libs/mlx-swift 4926d3d9 -> c633d221, the revision 2beb401f's Package.swift declares; mlx-swift main (52c36f86) has the same tree. SDK main calls mlx-swift APIs that 4926d3d9 lacks (MLXArray.sharingArray, the fencedInputs argument of MLXFast.metalKernel). The nested mlx-c moves from 004c735f to 2ac897e3 with it. - libs/mlx 31f550af -> 72dffa2d, the nested copy that Cmlx compiles at c633d221 (Source/Cmlx/mlx); mlx main (f24d7e63) has the same tree. 72dffa2d keeps the 0.10.3 M5 NAX head-dim split JIT fix: 31f550af is not its ancestor, but that fix's squash on mlx main (6bc9de5b, Layr-Labs/mlx#48, identical patch ID) is, and its jit_kernels.cpp change is intact. #1645 pins the same mlx-swift and mlx commits. Provider follow-ups for the SDK's new enum cases, identical to #1645's (46f7ae9 and 2185dfe) so the two branches merge without conflicts: - MLXServerGenerationEvent.logprobs is token metadata. The GLM and JSON answer-format observers and seven test helpers treat it like .info. No SDK engine or provider bridge emits it today; the provider sends logprobs through EngineV2LogprobsChannel. - MLXOpenAIServiceError.responseFormatCutOffByMaxTokens, which the SDK split from invalidResponseFormatOutput for a structured answer cut off by max_tokens, keeps that case's 422 and retryable classification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SDK main moved from the #369 squash (25bcd63f) to 2beb401f (#368). #368 only adds demandedLatestCheckpointMinimumTokens, which is nil by default and unset by this PR, so behaviour here is unchanged. With the same SDK pin as #1643, the two PRs merge cleanly in either order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gajesh2007
left a comment
There was a problem hiding this comment.
Approved for 0.10.5 (Gajesh).
…prompt end (−16.5% follow-up TTFT) (#1643) * perf(provider): restore dense Qwen conversations from just below the prompt end A dense Qwen 3.5/3.8 request served alone prefills in 4,096-token stripes, so its deepest SSD checkpoint was the last full stripe end, up to 4,095 tokens before the prompt end. The next turn of the conversation re-prefilled that gap. With its paged complete store, the engine now sets the SDK's demandedLatestCheckpointMinimumTokens to the store floor. A request the store would write then also ends a prefill range at the deepest 256-aligned boundary at least 64 tokens below its prompt end, when that saves at least the floor. Busy providers, which prefill in 512-token chunks beside decoding requests, keep the ordinary geometry. Six-turn conversation from 30K to 55K tokens, Qwen3.5-9B, M3 Ultra, two runs per arm: the mean summed time to first token of the five follow-up turns fell from 57.38 s to 47.88 s (-16.5%), with outputs identical to master on every turn. SSD bytes rose 2.6% (2.71 GB to 2.78 GB) for the same 7 files. Requires mlx-swift-lm 05c7ca7e (feat/demanded-latest-checkpoint). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(provider): pin mlx-swift-lm 76ff231b (docs for the end-of-prompt boundary) The SDK change adds demandedLatestCheckpointMinimumTokens to the retention doc and shortens its code comments. No code changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Repin the SDK to the merged #368 (2beb401f) and the MLX stack it declares Layr-Labs/mlx-swift-lm#368 was squash-merged as 2beb401f, so this branch's former SDK pin 76ff231b (#368's head) is not on SDK main. Every gitlink now points at a commit on its fork's main: - libs/mlx-swift-lm 76ff231b -> 2beb401f, the tip of SDK main and the #368 squash. Merging 76ff231b into the previous main (25bcd63f) gives exactly 2beb401f's tree, so #368 (demandedLatestCheckpointMinimumTokens) is unchanged. The pin also brings what SDK main gained since master's aee6ebb6: the tensor-parallel engine (#308), Qwen tensor batching (#352) and the optional stop-string scope (#369). - libs/mlx-swift 4926d3d9 -> c633d221, the revision 2beb401f's Package.swift declares; mlx-swift main (52c36f86) has the same tree. SDK main calls mlx-swift APIs that 4926d3d9 lacks (MLXArray.sharingArray, the fencedInputs argument of MLXFast.metalKernel). The nested mlx-c moves from 004c735f to 2ac897e3 with it. - libs/mlx 31f550af -> 72dffa2d, the nested copy that Cmlx compiles at c633d221 (Source/Cmlx/mlx); mlx main (f24d7e63) has the same tree. 72dffa2d keeps the 0.10.3 M5 NAX head-dim split JIT fix: 31f550af is not its ancestor, but that fix's squash on mlx main (6bc9de5b, Layr-Labs/mlx#48, identical patch ID) is, and its jit_kernels.cpp change is intact. #1645 pins the same mlx-swift and mlx commits. Provider follow-ups for the SDK's new enum cases, identical to #1645's (46f7ae9 and 2185dfe) so the two branches merge without conflicts: - MLXServerGenerationEvent.logprobs is token metadata. The GLM and JSON answer-format observers and seven test helpers treat it like .info. No SDK engine or provider bridge emits it today; the provider sends logprobs through EngineV2LogprobsChannel. - MLXOpenAIServiceError.responseFormatCutOffByMaxTokens, which the SDK split from invalidResponseFormatOutput for a structured answer cut off by max_tokens, keeps that case's 422 and retryable classification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: jonathan308 <5055076+jonathan308@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Freshness refresh: #1643, the base of this PR, merged into master (squash 6a78624) together with #1638, #1645, #1657, #1641, #1613 and #1676, so this PR now targets master. The text merge has no conflicts. The SDK gitlink keeps this PR's 9c2f47b6, which is master's pin 2beb401f plus this PR's SDK change; the diff against master is unchanged from the diff against the old base. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Freshness refresh: #1643, the base of this PR, merged into master (squash 6a78624) together with #1638, #1645, #1657, #1641, #1613 and #1676, so this PR now targets master. The text merge has no conflicts. The SDK gitlink keeps this PR's aabf0189, which is master's pin 2beb401f plus this PR's SDK change; the diff against master is unchanged from the diff against the old base. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#1645 merged as squash e7f9818, so this branch's #1645 commits no longer match master. The result is master plus only this PR's own changes (the same +/- lines as 2841c6f..75abd7d outside libs/). libs/mlx-swift-lm moves to 5ffbb801, the same two SDK commits replayed on master's pin 2beb401f (branch fix/reasoning-stop-scope-exclude-on-2beb401f; diff identical to 25bcd63f..25e65afc). libs/mlx-swift and libs/mlx stay at master's c633d221 and 72dffa2d. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings the 13 changes that landed on master only into dev, so the next dev release and the move to master contain them: SSD cache work (Layr-Labs#1641, Layr-Labs#1642, Layr-Labs#1643, Layr-Labs#1647, Layr-Labs#1648, Layr-Labs#1649, Layr-Labs#1651, Layr-Labs#1657 and the test fixture fix 093aaf3), overlapped weight hashing (Layr-Labs#1638), GPT-OSS stop sequences in the Harmony final message (Layr-Labs#1645), faster reconnects (Layr-Labs#1613) and the provider 0.10.5 preparation (Layr-Labs#1678). Layr-Labs#1659 is master's copy of dev's Layr-Labs#1658. Conflicts: the reconnect loop keeps dev's cluster-member handling and takes master's reconnect policy (the member-aware delay now starts from the policy's range, and the session is marked open after registration for both roles). The bridge passes both dev's default max-token context limit and master's stop-string scope. WeightHasher takes master's overlapped reads with dev's reason for reading uncached. Four case lists were the same set in a different order, a test-budget line differed only in wrapping, and two docs needed both sides. libs/mlx-swift-lm moves to mlx-swift-lm main 2beb401f, which contains dev's d5bd32b8 and master's Layr-Labs#368 and Layr-Labs#369. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Git merged three things from master that clash with dev without flagging them. InferenceErrorClassifier: master's Layr-Labs#1645 added responseFormatCutOffByMaxTokens to the retryable tool-noncompliance case, ahead of dev's own client-error case for it, so a response_format answer cut off by the client's max_tokens was reported as retryable; dev's file is restored (LocalContentPartRefusalTests covers it). Five tests: master added logprobs cases that dev's switches already handled; dev's files are restored. changelog.d/qualify-sdk-prod-identity.md is dev's Layr-Labs#1658 fragment, which master's 0.10.5 section already lists (Layr-Labs#1659), so it is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Master's Layr-Labs#1645 made client stop strings on GPT-OSS match only in the Harmony final message, so reasoning text can no longer end a request with an empty answer. Dev's distributed engine built its bridge without the scope and made its detokenizer without the request's scope, so cluster pairs serving GPT-OSS (gptossLayerStage) kept the old behaviour. The bridge now takes ModelEOSPolicy.stopStringScope like the single-Mac slot, and admission passes request.stopStringScope to the detokenizer; the bridge's own check of which stop sequence ended generation uses the same scope. For every other model the scope is nil and nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Fixes the empty gpt-oss answers OpenRouter reported (reasoning-only responses counted as silent failures). The engine matched a client
stopsequence against everything gpt-oss generated, including the private Harmony analysis. A stop string that appeared while the model was reasoning ended the request before any answer existed:finish_reason: "stop", reasoning only, emptycontent. Stops now match only in the Harmonyfinalmessage, the text clients receive ascontent. Other models are unchanged.The engine half is Layr-Labs/mlx-swift-lm#369, merged. This PR pins the MLX stack at the merged SDK main, as #1596 did (
46f7ae9c5):libs/mlx-swift-lm2beb401f(SDK main: the #369 squash25bcd63fplus #368, which only addsdemandedLatestCheckpointMinimumTokens, nil by default and unset here, so this PR's behaviour is unchanged; it is the same SDK pin as #1643, so the two merge cleanly in either order), pluslibs/mlx-swiftc633d221(nestedmlx72dffa2d,mlx-c2ac897e3) andlibs/mlx72dffa2d, because SDK main callsmlx-swiftAPIs newer than the old pin. All three are on their repos' main.72dffa2dkeeps the M5 NAX head-dim split attention JIT fix (mlx main6bc9de5b, sameget_steel_attention_nax_kernelchange as the 0.10.3 hotfix). Provider adaptations for the new SDK enum cases are behavior-preserving:.logprobsevents are handled like.info;responseFormatCutOffByMaxTokenskeeps the 422/retryable mapping of theinvalidResponseFormatOutputcase it was split from.Linked issue
OpenRouter report, 2026-10-27: ~15% of gpt-oss-20b requests counted as silent failures; 12.7% of responses contain only reasoning (competitors 1.5% / 0.5%).
Before
After
The scope (
ModelEOSPolicy.stopStringScope→GPTOSSHarmonyTemplateFix.finalChannelStopScope) travels with the existing EOS policy:EngineV2SlotFactory→EngineV2Factory.makeBridge→EngineV2Bridge.stopStringScope→EngineV2Translation.cbv2Request→CBv2Request.stopStringScope.EngineV2Bridge.matchedStopSequencereplays the same scope, so a candidate seen only in the analysis is never reported as the stop that matched.Test plan
Reproductions use the production artifact:
gpt-oss-20b2026-05-25-r1, aggregate61bfc04e…, 10/10 file SHA-256s verified against the production manifest. Paged KV and prefix cache were confirmed live by metrics at every server start, and every server was started cold with the same config.The bug, on master
8effff7f7(0.10.4, binary1de54ae6…). 18 prompts × 2 seeds per stop set,temperature1.0,max_tokens2048:stop"\n\n""\nUser:","\nHuman:""\nObservation:"".""Proven" means the empty response's reasoning is an exact prefix of its same-seed no-stop twin's reasoning, the twin continues with the stop string, and the twin produced an answer.
The fix, same prompts, seeds, weights and config. The final binary is built from exactly this PR's commit
41dd24f49+ SDK38b90ed1(binary1cfe15a9…, metallib6ccc6296…, ready 19 s). The pre-refactor build4d065c21…gave the identical table.stop"\n\n""\nUser:","\nHuman:""\nObservation:""."The same request ("What is the capital of Australia?", seed 11,
stop: ["."]) goes fromcontent: ""(reasoning cut at "The answer: Canberra") tocontent: "The capital of Australia is Canberra"with the full reasoning intact.No M5 attention-crash regression.
get_steel_attention_nax_kernelin the newmlx72dffa2dis byte-identical to the shipped 0.10.3 hotfix31f550af(via upstream6bc9de5b, feat: add filter token usage by model view #48). On the merged head (faa3407ec, binarya8e298c1…), M5 Max served Gemma 4 26B QAT prompts of 1,112, 2,060, 8,203 and 32,780 tokens: all complete, repeats hit the prefix cache, no Metal library build failure or trap in the server log. gpt-ossstop: ["."]returns "The capital of Australia is Canberra".On the re-pinned SDK-main stack (binary
8d8dd790…, metallib98bab9d7…):No other silent-empty mechanism found.
max_tokens4096 truncation correctly reported asfinish_reason: "length".Performance. Alternating fix/base server blocks (4 each, identical requests,
max_tokens768, one at a time):SDK unit tests (
libs/mlx-swift-lm).swift test --filter 'CBv2SamplingScopedStopHoldbackTests|CBv2SamplingStopHoldbackTests': 16/16.xcodebuild test -scheme mlx-swift-lm-Package -destination 'platform=macOS' -skipPackagePluginValidation -only-testing:…passed before the refactor pass (15/15).final <|constrain|>jsonheader; a stop never spanning a closer; a malformed header; held marker text released at the end.Provider unit tests.
swift build --build-tests, staged test metallib, thenswift test --skip-build --no-parallel --filter 'EngineV2MatchedStopSequenceTests|gptOss…|harmonyEOS…|nonHarmonyEOS…|PrefixCacheReceipt|EngineV2Bridge'with isolated state files: 141 tests in 20 suites passed. The new tests cover:model_type; Gemma and Qwen get none;git diff --check,python3 scripts/changelog.py check, andmake docs-impact-check BASE=origin/masterall pass.Full provider suite in CI (run 40644353914, attempt 2):
✔ Test run with 5812 tests in 808 suites passed after 802.359 seconds.The job then hit the CI watchdog's 900-second budget during the isolated gates that run after the suite (result.json:timed_out: true,elapsed_seconds: 901). The same deadline failure appears on unrelated branches today (perf/ssd-root-maintenance-header-cache,codex/prompt-cache-batch-hits). Attempt 1 lost its self-hosted runner. Provider SDK Tests, Release Integrity, Commit Signatures, Docs Impact/Lint and Prompt Parity pass.Components touched
libs/mlx-swift-lmpin)Protocol / interface changes
stopsemantics for GPT-OSS now match OpenAI-compatible behavior (stops apply to returned text). The reportedstop_sequencefollows the same scope.Documentation impact
docs/architecture/inference.md(stoprow);changelog.d/gptoss-stop-in-final-channel.md.Refactor pass
Independent subagent: CHANGED, behavior-preserving. It was verified with a 200,000-case randomized differential harness: unscoped output is identical to the old code, and scoped output is identical before and after the pass.
maxHold.testHeldMarkerTextIsReleasedAtTheEnd.Documented, not changed: in the generic API, a stop that ends inside a closer split across chunks can match before the closer is seen. For Harmony through the engine, closers are single special tokens that arrive whole (0 differences with whole-token chunking), so the type doc states the assumption.
Out of scope, noted for follow-up:
engineStopStrings: modelType != "flint"). Gemma 4 thought channels and Qwen<think>likely have the same exposure, and the new scope type can express their markers.provider-swift/Package.resolvedis unchanged here; a local build re-resolved swift-syntax 603.0.2 and that change is not committed.Merge order
Merge CBv2: optional stop-string scope so reasoning text cannot end a request mlx-swift-lm#369(merged 2026-10-28).🤖 Generated with Claude Code